<div id="addresslist"></div>
<div class="infolist clbd_b address-form zhbform" style="display: none;">
    <?php
    $this->breadcrumbs = $this->pageTitle = '地址管理';
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'address-form',
        'enableClientValidation' => true,
        'clientOptions' => array(
            'validateOnSubmit' => true,
        ),
    ));
    ?>
    <?php echo $form->errorSummary($model); ?>
    <div class="cols1 cl tm20">
        <div class="col cl">
            <div class="tit"><?php echo $form->labelEx($model, 'area'); ?></div>
            <div class="inp cl">
                <div class="select z">
                    <select id ="province" name="HomeForm[province]" ></select>           
                </div>
                <div class="select z lm15">
                    <select id ="city" name="HomeForm[city]" ></select>
                </div>
                <div class="select z lm15">
                    <select id ="area" name="HomeForm[area]" ></select>
                </div>
                <div class="select z lm15">
                    <select id ="street" name="HomeForm[street]" ></select>
                </div>
            </div>
        </div>
    </div>
    <div class="cols2 cl tm10">
        <div class="col cl">
            <div class="tit"><?php echo $form->labelEx($model, 'streetDetail'); ?></div>
            <div class="inp cl"><div class="text"><?php echo $form->textField($model, 'streetDetail', array('style' => 'width:365px')); ?><span></span></div></div>
        </div>
        <div class="col cl">
            <div class="tit"><?php echo $form->labelEx($model, 'postalcode'); ?></div>
            <div class="inp cl"><div class="text"><?php echo $form->textField($model, 'postalcode', array('style' => 'width:165px')); ?><span></span></div></div>
        </div>
    </div>
    <div class="cols1 cl tm10">
        <div class="col cl">
            <div class="tit"><?php echo $form->labelEx($model, 'recipients'); ?></div>
            <div class="inp cl"><div class="text"><?php echo $form->textField($model, 'recipients', array('style' => 'width:165px')); ?><span></span></div></div>
        </div>
    </div>
    <div class="cols1 cl tm10">
        <div class="col cl">
            <div class="tit"><?php echo $form->labelEx($model, 'mobile'); ?></div>
            <div class="inp cl"><div class="text"><?php echo $form->textField($model, 'mobile', array('style' => 'width:165px')); ?><span></span></div></div>
        </div>
    </div>
    <div class="cols1 cl tm10">
        <div class="col cl">
            <div class="tit"><?php echo $form->labelEx($model, 'telephone'); ?></div>
            <div class="inp cl"><div class="z"><div class="text"><?php echo $form->textField($model, 'areacode', array('style' => 'width:70px', 'placeholder' => '区号')); ?><span></span></div></div><div class="z lm18"><div class="text"><?php echo $form->textField($model, 'phonenum', array('style' => 'width:153px', 'placeholder' => '座机号码')); ?><span></span></div></div><div class="z lm18"><div class="text"><?php echo $form->textField($model, 'extension', array('style' => 'width:70px', 'placeholder' => '分机号')); ?><span></span></div></div></div>
        </div>
    </div>
    <div class="cols1 cl tm10">
        <div class="col cl">
            <div class="tit"></div>
            <div class="inp cl">
                <div class="z"><?php echo $form->checkBox($model, 'default'); ?><?php echo $form->label($model, 'default'); ?></div>
                <?php echo CHTML::ajaxSubmitButton('添加', Yii::app()->baseUrl . '/ajax/account/?mod=addUserContactInfo', array('dataType' => 'json', 'success' => 'js:function(json){if (json.content) { $(target).html(json.content);}if (json.callback) {eval(json.callback);}}'), array('class' => 'submit submit_green z', 'style' => 'margin-left:20px;')) ?>
                <div class="z"><?php echo $form->error($model, 'postalcode'); ?></div>
            </div>
        </div>
    </div>
    <?php $this->endWidget(); ?>
</div>
<script>
    $(document).ready(function() {
        ajaxGet('#addresslist', 'getUserContactInfo', 'account', 'html');
        
        ajaxPost('#province','getAddressList',{'type':1,'parentId':0},'account','html');
        ajaxPost('#city','getAddressList',{'type':2,'parentId':0},'account','html');
        ajaxPost('#area','getAddressList',{'type':3,'parentId':0},'account','html');
        ajaxPost('#street','getAddressList',{'type':4,'parentId':0},'account','html');
        
        $("#province").change(function(){
            var parentId = $(this).children('option:selected').val();
            ajaxPost('#city','getAddressList',{'type':2,'parentId':parentId},'account','html');
            if(parentId == 0){
                $("#area").empty();
                $("<option value='0'>请选择</option>").appendTo("#area");
                $("#street").empty();
                $("<option value='0'>请选择</option>").appendTo("#street");
            };
        });
        
        $("#city").change(function(){
            var parentId = $(this).children('option:selected').val();
            ajaxPost('#area','getAddressList',{'type':3,'parentId':parentId},'account','html');
            if(parentId == 0){
                $("#street").empty();
                $("<option value='0'>请选择</option>").appendTo("#street");
            };
        });
        
        $("#area").change(function(){
            var parentId = $(this).children('option:selected').val();
            ajaxPost('#street','getAddressList',{'type':4,'parentId':parentId},'account','html');
        });
        
    });
</script>